package cn.dada.dadarecipes.user.shipping_address.controller;

import cn.dada.dadarecipes.base.response.JsonResult;
import cn.dada.dadarecipes.user.shipping_address.pojo.dto.ShippingAddressParam;
import cn.dada.dadarecipes.user.shipping_address.pojo.vo.ShippingAddressVO;
import cn.dada.dadarecipes.user.shipping_address.service.ShippingAddressService;
import cn.dada.dadarecipes.user.user.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "01.02收货地址模块")
@Slf4j
@RestController
@RequestMapping("/v1/user")
public class ShippingAddressController {
    @Autowired
    ShippingAddressService shippingAddressService;

    @ApiOperation(value = "收货地址新增")
    @PostMapping("/insertAddress")
    public JsonResult insertAddress(ShippingAddressParam shippingAddressParam) {
        log.debug("用户新增地址:shippingAddressParam={}", shippingAddressParam);
        shippingAddressService.insertAddress(shippingAddressParam);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除收货地址")
    @PostMapping("/deleteAddress/{id}")
    public JsonResult deleteAddress(@PathVariable Long id) {
        log.debug("删除收货地址:id={}", id);
        shippingAddressService.deleteAddress(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "用户地址查询功能")
    @GetMapping("/selectAddress")
    public JsonResult query(ShippingAddressParam shippingAddressParam) {
        log.debug("用户地址查询:shippingAddressParam={}",shippingAddressParam);
        List<ShippingAddressVO> shippingAddressVO = shippingAddressService.query(shippingAddressParam);
        return JsonResult.ok(shippingAddressVO);
    }
}